home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_22_1988_Transactor_Publishing.d64
/
sort demo update
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2023-02-26
|
639b
|
27 lines
10 input"how many names";n
20 dim a(n),b(n),a$(n),t$(n)
30 for j=1 to n: print: print"number";j
40 input"surname";s$
50 input"first name";f$
60 t$(j)=s$+", "+f$: rem combine surnames with last names
70 input"age";a$(j)
80 h=(j-1)/2: g=0
82 if (t$(j) < t$(a(h))) then h=int((h+g)/2): goto 86
84 g=h: h=int((h+j)/2)
86 if h-g > 0 then 82
88 h=h-(t$(j) > t$(a(h))): g=j-1
90 if g>=h then a(g+1)=a(g): g=g-1: goto 90
100 a(h)=j
110 b(j)=j: h=j+1
120 h=h-1: if a$(j)<a$(b(h-1))then b(h)=b(h-1): goto 120: rem sort ages
130 b(h)=j
140 next j
150 print: print"sorted alphabetically"
160 for j=1 to n
170 print t$(a(j)), a$(a(j))
180 next j
190 print:print" sorted by age:"
200 for j=1 to n
210 print t$(b(j)), a$(b(j))
220 next j